package com.sjqg.dao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.LinkedList;
import java.util.List;

import org.apache.commons.dbutils.ResultSetHandler;

import com.sjqg.model.Address;
import com.sjqg.model.Service;
import com.sjqg.model.ServiceType;
import com.sjqg.model.Technicain;
import com.sjqg.model.User;

public class AddressDao extends BaseDao implements ResultSetHandler<List<Address>>{
	
	public List<Address> getAddress(String id) {
		try {
			String sql = "select"
					+ " a.id,  a.name,  a.phone, a.province,  a.city,  a.detailaddress,  a.userid,"
					+ " u.id, u.nickname, u.name, u.phone, u.address, u.headimg"
					+ " from  users u"
					+ " right join address a on u.id = a.userId where u.id = ?";
			return queryRunner.query(sql , this, id);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return null;
	}
	
	@Override
	public List<Address> handle(ResultSet rs) throws SQLException {
		List<Address> list=new LinkedList<Address>();
		while(rs.next()) {
			list.add(new Address(rs.getString("id")
					, rs.getString("name")
					, rs.getString("phone")
					, rs.getString("province")
					, rs.getString("city")
					, rs.getString("detailAddress")
					, new User(rs.getString("id")
							, rs.getString("nickName")
							, rs.getString("name")
							, rs.getString("phone")
							, rs.getString("address")
							, rs.getString("headImg")))
			);
		}
		return list;
	}

}
